package com.lh.oauth;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import com.lh.entity.OpenUser.OpenUserType;
import com.lh.oauth.impl.BaiduOAuth;
import com.lh.oauth.impl.QQOAuth;
import com.lh.oauth.impl.SinaOAuth;

/**
 * @author liuhui
 * @version 1.0
 * @date 2013-4-29 下午4:48:41
 */
@Component
public class OAuthFactory implements ApplicationContextAware {

	private ApplicationContext ac;
	
	private static Map<OpenUserType, Class<? extends OAuth>> map = new HashMap<OpenUserType, Class<? extends OAuth>>();
	static{
		map.put(OpenUserType.QQ, QQOAuth.class);
		map.put(OpenUserType.SINA, SinaOAuth.class);
		map.put(OpenUserType.BAIDU, BaiduOAuth.class);
	}
	
	
	public OAuth getOAuth(OpenUserType type ){
		if(type == null ){
			return null;
		}
		return ac.getBean( map.get(type));
	}
	
	@Override
	public void setApplicationContext(ApplicationContext ac) throws BeansException {
		this.ac = ac;
	}

}
